package org.iogame.action;

import com.iohao.game.action.skeleton.core.BarSkeleton;
import com.iohao.game.action.skeleton.core.BarSkeletonBuilderParamConfig;
import com.iohao.game.action.skeleton.core.flow.interal.DebugInOut;
import com.iohao.game.bolt.broker.client.AbstractBrokerClientStartup;
import com.iohao.game.bolt.broker.core.client.BrokerAddress;
import com.iohao.game.bolt.broker.core.client.BrokerClient;
import com.iohao.game.bolt.broker.core.client.BrokerClientBuilder;
import com.iohao.game.bolt.broker.core.common.BrokerGlobalConfig;
import com.iohao.game.common.kit.NetworkKit;
import lombok.extern.slf4j.Slf4j;
import org.iogame.util.ClsUtil;

/**
 * @author lc
 * @since 2022/10/26
 */
@Slf4j
public class DemoSpringLogicServer extends AbstractBrokerClientStartup {
    @Override
    public BarSkeleton createBarSkeleton() {

        var config = new BarSkeletonBuilderParamConfig()
                .addActionController(TestAction.class);

        // 开启广播日志
        config.setBroadcastLog(true);

        var builder = config.createBuilder();
        builder.addInOut(new DebugInOut());

        // io-game-test
        ClsUtil.scanPackage(TestAction.class); //扫描包
        builder.setActionAfter(new TestActionAfter()); //自定义发送请求处理

        return builder.build();
    }

    @Override
    public BrokerClientBuilder createBrokerClientBuilder() {
        BrokerClientBuilder builder = BrokerClient.newBuilder();
        builder.appName("demo spring 游戏逻辑服");
        return builder;
    }

    @Override
    public BrokerAddress createBrokerAddress() {
        // 类似 127.0.0.1 ，但这里是本机的 ip
        String localIp = NetworkKit.LOCAL_IP;
        // broker （游戏网关）默认端口
        int brokerPort = BrokerGlobalConfig.brokerPort;
        return new BrokerAddress(localIp, brokerPort);
    }
}
